package com.api.v1.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dao.SeckillgoodsDAO;
import com.pojo.Seckillgoods;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class SeckillGoodsService extends ServiceImpl<SeckillgoodsDAO, Seckillgoods> {

    @Autowired
    private SeckillgoodsDAO seckillgoodsDAO;


    /**
     * 根据主键查找秒杀记录
     * 1.如果缓存中存在，则直接返回缓存中数据
     * 2.如果缓存中不存在，则查数据库
     * 3.如果数据库中存在，则存到缓存中去
     * @return
     */
    @Cacheable(cacheNames = "seckillGoods",key = "#id")
    public Seckillgoods findById( long id)
    {
        return seckillgoodsDAO.selectById(id);
    }


    @Cacheable(cacheNames = "seckillGoods",key = "'findAll'")
    public List getAllSeckillGoods()
    {
      QueryWrapper queryWrapper = new QueryWrapper();
      queryWrapper.gt("kuchun",0);
      List list = seckillgoodsDAO.selectList(queryWrapper);
      return list;
    }
}
